/* ---<>-----------------------------------
        Includes
---------------------------------------- */
#include <inttypes.h>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "allocations/daq.h"
#include "util/util.h"
#include "stopWatch.h"
#include "allocations/comPort.h"
#include "global.h"

#include "highLevel.h"

#include <math.h>


double bigAssChunkOfData[28000];
/* ---<>-----------------------------------
        Namespaces
---------------------------------------- */
using namespace std;
using namespace DAQ_namespace;




/* ---<>-----------------------------------
      main()
---------------------------------------- */
int main()
{
    uint8_t initialized,i;


    GAIN_ENUM       ADC_GAIN[4] = {ADC_CH_GAIN_1X_gc,ADC_CH_GAIN_1X_gc,ADC_CH_GAIN_1X_gc,ADC_CH_GAIN_1X_gc};

    uint8_t         DAC_Enable_msk = DAC_CH0_bp | DAC_CH1_bp;

    PLOC_ENUM       ENC_PLOC[2] = {PLOC_NULL,PLOC_NULL};

    uint16_t        ENC_RES[2] = {512,512};

    uint8_t         servoMsk = 0x0;
    uint8_t         motorMsk = 0x0;

    uint16_t        inputPinMsk = 0x1FFF;
    uint16_t        outputPinMsk = 0x0;

    uint16_t        freq = 1;


    stopWatch delayTimer,timer2;
    delayTimer.start();
//    timer2.start();

    //start port
    comPortInit(1000000,2,2);

    initialized = init(ADC_GAIN,DAC_Enable_msk,ENC_PLOC,ENC_RES,servoMsk,motorMsk,inputPinMsk,outputPinMsk,freq);

    uint16_t analogOut[2] = {0,0x3FF};
    uint16_t inc = 0;
    if(initialized)
    {
        asm("nop");
        for(inc=0;inc<1000;inc++)read(0,bigAssChunkOfData,7000);
    /*    for(inc = 0; inc < 60000;inc++)
        {
            delayTimer.start();

            delayTimer.pause(.001);
         //   read(0,bigAssChunkOfData,7);
            DAQ.sendOutputSuperPacket(analogOut,0,0);
            analogOut[0] ^= 0x3FF;
            analogOut[1] ^= 0x3FF;
            while(delayTimer.split()<.002);
        }
    */

    //    example();
    }
    printf("\n\nStoping Daq \n");

    DAQ.sendStopProgram();
    DAQ.sendReset();
    delayTimer.pause(.1);
    FT_Close(handle);
	return 0;
}







